<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>liugui</title>
    <script>
        function validateForm() {
            var x = document.forms["myForm"]["fname"].value;
            if (x == null || x == "") {
                alert("姓必须填写");
                return false;
            }
        }
    </script>
</head>

<body>
    <!-- form表单 -->
    <form name="myForm" action="" onsubmit="return validateForm()" method="post">
        姓: <input type="text" name="fname">
        <input type="submit" value="提交">
    </form>

</body>

</html>